package com.example.demo.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import com.example.demo.dto.LoginRequestDto;
import com.example.demo.dto.LoginResponseDto;
import com.example.demo.entity.EmployeeEntity;
import com.example.demo.mapper.EmployeeMapper;
import com.example.demo.service.LoginService;

@Service
public class LoginServiceImpl implements LoginService {

	@Resource
	private EmployeeMapper employeeMapper;

	/**
	 * ログイン
	 * 
	 * @param requestDto
	 * @return LoginResponseDto
	 */
	public LoginResponseDto login(LoginRequestDto requestDto) {

		// 社員情報を取得する
		List<EmployeeEntity> resultList = employeeMapper.login(requestDto);
		// 検索結果判定
		LoginResponseDto loginResponseDto = new LoginResponseDto();
		if (resultList != null && resultList.size() == 1) {
			BeanUtils.copyProperties(resultList.get(0), loginResponseDto);
			loginResponseDto.setDivisionCode(resultList.get(0).getDivision());
			loginResponseDto.setProcessingResult("1");
		} else {
			loginResponseDto.setProcessingResult("0");
		}
		return loginResponseDto;
	}

}
